<?php include "../public/header.php"?>
<?php include "../public/header_public.php"?>
<body class="laytp-container">
<div style="height: 45px"></div>
<div id="opt_nav">
</div>
<div id="dialog">
    <div class="page-title" id="page-title">
        <div class="page-title-con">
            <span class="title">选择成本价格库信息-材料</span>
            <div class="move_title"></div>
            <div class="page-title-opt-list">
                <button class="layui-btn layui-btn-sm btn-dark marginr5" type="button" id="submit">确定</button>
                <span id="page-close" class="page-close" onclick="layer_close()">×</span>
            </div>
        </div>
    </div>
</div>
<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">分类</label>
                        <div class="layui-input-block">
                            <div id="basetype_cai" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">施工地点</label>
                        <div class="layui-input-block">
                            <input type="text" name="areas" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">工程名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">项目类型</label>
                        <div class="layui-input-block">
                            <div id="xiangtype" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">签约年度</label>
                        <div class="layui-input-block">
                            <input type="text" name="shidt" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">供货方式</label>
                        <div class="layui-input-block">
                            <div id="gongtype_cai" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">材料品牌或厂商</label>
                        <div class="layui-input-block">
                            <input type="text" name="painame" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">材料名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="pinname" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">规格型号</label>
                        <div class="layui-input-block">
                            <input type="text" name="guige" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">计量单位</label>
                        <div class="layui-input-block">
                            <input type="text" name="valunit" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">不含税单价</label>
                        <div class="layui-input-block">
                            <input type="text" name="noratefee" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">供货负责人</label>
                        <div class="layui-input-block">
                            <input type="text" name="gongname" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">联系方式</label>
                        <div class="layui-input-block">
                            <input type="text" name="gongtel" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">价格日期</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="pridt" placeholder="请输入" autocomplete="off" class="layui-input bdate_sea_range_ymd">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">备注1</label>
                        <div class="layui-input-block">
                            <input type="text" name="explain" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">备注2</label>
                        <div class="layui-input-block">
                            <input type="text" name="explaintwo" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                                <div id="search_open" onclick="toggle_search()">
                                    <i class="layui-icon layui-icon-down"></i>展开
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md12" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    var choose_type = getQueryVariable('choose_type');
    if(choose_type === undefined || choose_type === false){
        choose_type = 'radio';
    }else{
        choose_type = 'checkbox';
    }
    var parent_domkey = getQueryVariable('domkey');
    var parent_page = getQueryVariable('page');

    layui.use(["laytp",'laypage','table','dropdown','form','soulTable'], function () {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;

        $('#TableSearchReset').click(function () {
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });

        $("#cols_table").hide();
        $("#export_table").hide();
        table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_check_main_base_cai),where: {}, page: true, height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: ['', '', ''],filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response,contextmenu:get_table_contextmenu(soulTable)
            ,parseData: function(res){

                xmselect_dan('basetype_cai', res.data.basetype_cai, res.data.is_basetype_cai, function (res) {
                    setTimeout(function () {
                        searchTableFunc(form, table);
                    },100)
                });
                xmselect_dan('xiangtype', res.data.xiangtype, res.data.is_xiangtype, function (res) {
                    setTimeout(function () {
                        searchTableFunc(form, table);
                    },100)
                });
                xmselect_dan('gongtype_cai', res.data.gongtype_cai, res.data.is_gongtype_cai, function (res) {
                    setTimeout(function () {
                        searchTableFunc(form, table);
                    },100)
                });

                render_from();
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data.data
                };
            }
            ,cols: [[
                {type:choose_type,fixed:'left'}
                ,{field: 'basetype_cai', title: '分类'}
                ,{field: 'areas', title: '施工地点'}
                ,{field: 'name', title: '工程名称'}
                ,{field: 'xiangtype', title: '项目类型'}
                ,{field: 'shidt', title: '签约年度'}
                ,{field: 'gongtype_cai', title: '供货方式'}
                ,{field: 'painame', title: '材料品牌或厂商'}
                ,{field: 'pinname', title: '材料名称'}
                ,{field: 'guige', title: '规格型号'}
                ,{field: 'valunit', title: '计量单位'}
                ,{field: 'noratefee', title: '不含税单价'}
                ,{field: 'gongname', title: '供货负责人'}
                ,{field: 'gongtel', title: '联系方式'}
                ,{field: 'pridt', title: '价格日期'}
                ,{field: 'explain', title: '备注1'}
                ,{field: 'explaintwo', title: '备注2'}
            ]]
            ,done : function(res, curr, count){
                $(".layui-table-tool").remove()
                soulTable.render(this);
            }
        });
        listTableSearch(form, table);


        $('#submit').on('click', function () {
            var checkStatus = layui.table.checkStatus('datalist');
            var data = checkStatus.data;
            if(data.length < 1){
                facade.error("请选择数据");return false;
            }

            if(parent_page == 'mark'){
                $("#list_list tr", parent.document).eq(parent_domkey).find('.name').attr('source',data[0].id);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.basetype').val(data[0].basetype_cai);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.name').val(data[0].pinname);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.guige').val(data[0].guige);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.valunit').val(data[0].valunit);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.content_exp').val(1);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.content').val(1);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.loss_rate').val(0);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.no_price').val(data[0].noratefee);

                $("#list_list tr", parent.document).eq(parent_domkey).find('.opt_ru').addClass('layui-hide');
                $("#list_list tr", parent.document).eq(parent_domkey).find('.opt_cha').removeClass('layui-hide');
                $("#list_list tr", parent.document).eq(parent_domkey).find('.opt_qing').removeClass('layui-hide');

                if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                    window.parent.update_refresh_row_func();
                }
            }else{
                var str = '<button type="button" class="layui-btn layui-btn-sm btn-dark" key="'+data[0].id+'"><span class="choose_content">'+data[0].name+'('+data[0].accnum+')'+'' +
                    '</span><span class="choose_close" onclick="choose_close(this, \''+parent_dom+'\')">×</span></button>';
                $("#"+parent_dom , parent.document).html(str);
                parent.formValid(parent_dom);
            }

            layer_close();
        });

    });
</script>
</body>
</html>
